package com.coolbi.onsupai.admin.action;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.coolbi.onsupai.core.biz.OrderBiz;
import com.coolbi.onsupai.core.constant.OrderConstant;
import com.coolbi.onsupai.core.entity.Order;
import com.coolbi.onsupai.core.entity.OrderItem;
import com.coolbi.security.entity.User;
import com.coolbi.security.web.action.SessionAction;

/**
 * 
 * @Description Order Action
 * @author for2cold
 * @codeDate 2012-7-23 下午04:23:38
 * 
 */
public class OrderAction extends SessionAction {

	private static final long serialVersionUID = 1L;

	private Order order;
	private List<Order> orderList;
	@Autowired
	private OrderBiz orderBiz;
	private OrderItem orderItem;

	/**
	 * 提交订单
	 * @return
	 */
	public String save() {
		try {
			User user = getCurrentUser();
			order.setUserId(user.getId());
			order = orderBiz.saveOrder(order, orderItem, user.getId());
		} catch (Exception e) {
			e.printStackTrace();
			return ERROR;
		}
		return SUCCESS;
	}
	
	/**
	 * 根据ID集合查询订单
	 * @return
	 */
	public String findByIds() {
		try {
			order = orderBiz.get(order.getId());
		} catch (Exception e) {
			e.printStackTrace();
			return ERROR;
		}
		return SUCCESS;
	}
	
	/**
	 * 确认订单发货
	 * 
	 * @return
	 */
	public String confirmConsign() {
		orderBiz.confirmOrderConsign(order.getId(), OrderConstant.CONSIGNED);
		return SUCCESS;
	}
	
	/**
	 * 分页查看所有订单
	 * 
	 * @return
	 */
	public String listByPage() {
		try {
			pager.setRecordCount(orderBiz.count());
			orderList = orderBiz.listByPage((pager.getCurrPageNo() - 1) * pager.getPageSize(), pager.getPageSize());
		} catch (Exception e) {
			e.printStackTrace();
			return ERROR;
		}
		return SUCCESS;
	}
	
	public Order getOrder() {
		return order;
	}

	public void setOrder(Order order) {
		this.order = order;
	}

	public List<Order> getOrderList() {
		return orderList;
	}

	public void setOrderList(List<Order> orderList) {
		this.orderList = orderList;
	}

	public void setOrderBiz(OrderBiz orderBiz) {
		this.orderBiz = orderBiz;
	}

	public OrderItem getOrderItem() {
		return orderItem;
	}

	public void setOrderItem(OrderItem orderItem) {
		this.orderItem = orderItem;
	}
}
